<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Wall extends CI_Controller {

 
	function __construct()
	{
		parent::__construct();
		
		// check if user logged in 
		/*if (!$this->ion_auth->logged_in())
	  	{
			redirect('auth/login');
	  	}*/
		$this->load->model('user/user_model');
		$this->load->model('user/attendance_model');	
		$this->load->model('user/wall_model');
		$this->load->model('ion_auth_model');	
			
	}
		
   function index()
   {
	   	$page = $this->session->flashdata('page');	
	   	$meta['page_title'] = "My Wall";			
		$data['user'] = $this->wall_model->get_user_details($this->session->userdata('user_id'));
		$data['jobs'] = $this->wall_model->get_job_details();		
		//echo '<pre>';
		//print_r($data);
		$this->load->view('common/header', $meta);   
	   	$this->load->view('user/wall',$data);
       	$this->load->view('common/footer');
   }
   function edit_profile(){
   	$update_values = array(	
	'username' => $this->input->post('username'),
	'email' => $this->input->post('email'),
	'phone' => $this->input->post('phone'),
	'username' => $this->input->post('username'),
	//'password' => $this->ion_auth_model->hash_password($this->input->post('password')),	
	);
	
	$pass = $this->input->post('password');
	if(!empty($pass)){
	$update_values['password'] = $this->ion_auth_model->hash_password($this->input->post('password'));	
	}	
   	
	//print_r($update_values);
	$this->wall_model->edit_profile($update_values);
	$this->session->set_flashdata('msg','<i class="icon-ok-sign"></i> Profile Updated Successfully');
	redirect('user/wall','refresh');
   }
	
	function do_upload()
	{
		$config['upload_path'] = './assets/uploads/';
		$config['allowed_types'] = 'gif|jpg|png';
		$config['max_size']	= '1000';
		$config['max_width']  = '1024';
		$config['max_height']  = '768';
//exit;
		
		$this->load->library('upload', $config);

		if ( ! $this->upload->do_upload())
		{
			$error = array('error' => $this->upload->display_errors());
			//print_r($error);
			
			redirect('user/wall','refresh');
			//$this->load->view('upload_form', $error);
		}
		else
		{
			$data['upload_data' ] = ($this->upload->data());
			
			 
			$this->wall_model->do_upload($this->session->userdata('user_id'),$data['upload_data' ]['file_name']);
			
			$this->session->set_userdata('profile_image', $data['upload_data' ]['file_name']);
					
			redirect('user/wall','refresh',$data);
		}
	}
	
	function viewprofile($id=null)
	{
		//$data['userid'] = $id;
		if(isset($id))
		{
			$user= $id;
		}else
		{
			$user=$this->session->userdata('user_id');		
		}
		$data['userid'] = $user;
					
		//echo $id;
		//exit;
		//$users = $_REQUEST['user'];
		$data['getefficiencyid'] = $this->jobprofile_model->efficiency_getall_by_id($user);
		$data['efficiencychart'] = $this->jobprofile_model->efficiencychart($user);
		$data['efficiencyfields'] = $this->jobprofile_model->efficiencyfields($user);
		$data['skillschart'] = $this->jobprofile_model->skillschart($user);
		$data['toolschart'] = $this->jobprofile_model->toolschart($user);
		$data['hobbies'] = $this->jobprofile_model->hobbies_getall_by_id($user);
		$data['hobbyimage'] = $this->jobprofile_model->hobbyimage($user);
		$data['userdetails'] = $this->jobprofile_model->userdetails($user);
		$data['designationbyid'] = $this->jobprofile_model->designationbyid($user);
		$data['skillsimage'] = $this->jobprofile_model->skillsimage($user);
		$data['getskillsid'] = $this->jobprofile_model->skills_getall_by_id($user);
		$data['gettoolsid'] = $this->jobprofile_model->tools_getall_by_id($user);
		$data['user'] = $this->jobprofile_model->get_user_details($this->session->userdata('user_id'));
		$data['jobs'] = $this->jobprofile_model->get_job_details();
		//$data['query'] = $this->jobprofile_model->tools_getall();
		//$data['query'] = $this->jobprofile_model->hobbies_getall();

		$meta['page_title'] = "View Job Profile";
		$this->load->view('common/header',$meta);
		$this->load->view('user/view-jobprofile',$data);
		$this->load->view('common/footer');
		//echo $id;

	}
	
}
	
	?>